package com.yhy;

import com.yhy.wxzn.common.utils.PlcGetByte;
import com.yhy.wxzn.wcs.device.netty.bean.ResultData;

/**
 * @Auther: 97354
 * @Date: 2023/11/21 17:12
 * @Description: XJHelper
 * @Version 1.0.0
 */
public class XJHelper1 {
    public static void main(String[] args) {
        HslCommunication.XJHelper xjHelper = new HslCommunication.XJHelper("127.0.0.1",502,(byte) 1);
        xjHelper.connect("127.0.0.1");
        byte[] bytes = new byte[16];
        //任务号
        bytes[0] = (byte) ((0 >> 24) & 0xFF);
        bytes[1] = (byte) ((0 >> 16) & 0xFF);
        bytes[2] = (byte) ((0 >> 8) & 0xFF);
        bytes[3] = (byte) (0 & 0xFF);
        //载位信号
        bytes[4] = (byte) ((1 >> 8) & 0xFF);
        bytes[5] = (byte) ((1) & 0xFF);
        //有货信号
        bytes[6] = (byte) ((1 >> 8) & 0xFF);
        bytes[7] = (byte) ((1) & 0xFF);
        //状态
        bytes[8] = (byte) ((2 >> 8) & 0xFF);
        bytes[9] = (byte) ((2) & 0xFF);
        //故障码
        bytes[10] = (byte) ((1 >> 8) & 0xFF);
        bytes[11] = (byte) ((1) & 0xFF);
        //工作状态
        bytes[12] = (byte) ((1 >> 8) & 0xFF);
        bytes[13] = (byte) ((1) & 0xFF);

        xjHelper.writeBytes("D20000",bytes);
        ResultData resultData = xjHelper.readBytes("D20000",16);
        if (resultData.isSuccess()) {
            byte[] dataValue = (byte[]) resultData.getValue();
            int taskNo = PlcGetByte.bytesToInt32Hight(dataValue, 0);
            int zw = PlcGetByte.bytesToInt16Hight2(dataValue, 4);
            int yh = PlcGetByte.bytesToInt16Hight2(dataValue, 6);
            int zt = PlcGetByte.bytesToInt16Hight2(dataValue, 8);
            int gzm = PlcGetByte.bytesToInt16Hight2(dataValue, 10);
            int gzzt = PlcGetByte.bytesToInt16Hight2(dataValue, 12);
            System.out.println("[taskNo]:"+taskNo);
            System.out.println("[zw]:"+zw);
            System.out.println("[yh]:"+yh);
            System.out.println("[zt]:"+zt);
            System.out.println("[gzm]:"+gzm);
            System.out.println("[gzzt]:"+gzzt);

        }
    }
}
